package com.wc.alorithm_blue_bridge._思维.Q1368;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congge
 * @Date 2023/11/1 10:23
 * @description 盖世武功
 * https://www.lanqiao.cn/problems/1368/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=8
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        long n = sc.nextLong();
        long m = sc.nextLong();
        long ans = 0;
        while (m-- > 0) {
            long left = sc.nextLong();
            long right = sc.nextLong();
            long start = sc.nextLong();
            long end = sc.nextLong();
            ans += (right - left + 1) * (start + end) / 2;
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public long nextLong() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (long) in.nval;
        }
    }
}
